package com.ywm.eduService.controller;


import com.ywm.commonUtil.R;
import com.ywm.eduService.entity.EduChapter;
import com.ywm.eduService.entity.vo.ChapterVo;
import com.ywm.eduService.service.EduChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-05-18
 */
@RestController
@RequestMapping("/eduService/edu-chapter")
public class EduChapterController {
    @Autowired
    public EduChapterService chapterService;

    // 课程大纲列表
    // 传入课程ID
    @GetMapping("/getChapterVideo/{id}")
    public R getChapterVideo(@PathVariable("id") String id) {
        List<ChapterVo> videoByCourseId = chapterService.getChapterVideoByCourseId(id);
        return R.ok().data("allCourseIdVideo",videoByCourseId);
    }

    //添加章节
    @PostMapping("/addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter){
        boolean save = chapterService.save(eduChapter);
        if (save) {
            return R.ok();
        }else {
            return R.error();
        }
    }
    //查询章节
    @GetMapping("getChapterInfo/{id}")
    public R getChapterInfo(@PathVariable("id") String id) {
        EduChapter id1 = chapterService.getById(id);
        return R.ok().data("chapter",id1);
    }

    //修改章节
    @PostMapping("/updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){
        boolean save = chapterService.updateById(eduChapter);
        if (save) {
            return R.ok();
        }else {
            return R.error();
        }
    }

    //删除章节
    @DeleteMapping("deleteChapter/{id}")
    public R deleteChapter(@PathVariable("id") String id) {
        boolean b = chapterService.removeById(id);
        if (b) {
            return R.ok();
        }else {
            return R.error();
        }
    }
}

